home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 867 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.9 KB  |  55 lines

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: clamage@Eng.sun.com (Steve Clamage)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Quick questions
  5. Date: 26 Mar 1996 19:13:13 GMT
  6. Organization: Sun Microsystems Inc.
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <4j9f6i$s2o@engnews1.Eng.Sun.COM>
  9. References: <315837ce.67891262@sqarc.sq.com>
  10. Reply-To: clamage@Eng.sun.com
  11. NNTP-Posting-Host: taumet.eng.sun.com
  12. X-Nntp-Posting-Host: taumet.eng.sun.com
  13. Content-Length: 1026
  14. X-Lines: 31
  15. Originator: clamage@taumet
  16.  
  17. In article 67891262@sqarc.sq.com, clamage@taumet.eng.sun.com (Steve Clamage) writes:
  18. >clamage@Eng.sun.com (Steve Clamage) wrote:
  19.  
  20. >>>2) From a previous post on this group, it looks like the standard will
  21. >>>allow one to define conversion operators for pre-existing, source code
  22. >>>untouchable data types.  Yes? No? What will this look like? I have the
  23. >>>May copy of the WP, and don't see any mention of this.
  24. >>
  25. >>I'm not sure I understand what you are asking. If you mean can you define
  26. >>a conversion operator from a user-defined class to a predefined type
  27. >>like int or double, then yes, that has long been part of C++.
  28.  
  29. >I believe he was referring to something like
  30.  
  31. >class myclass{};
  32. >operator int(const myclass &arg);
  33. >
  34. >Just like the global equality operators, etc.
  35.  
  36. That is not allowed. A type conversion function must be a member of a class.
  37.  
  38. class myclass {
  39. public:
  40.     operator int(); // converts a myclass to an int
  41.     myclass(int); // converts an int to a myclass
  42. };
  43.  
  44. ---
  45. Steve Clamage, stephen.clamage@eng.sun.com
  46.  
  47.  
  48.  
  49.  
  50. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  51. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  52. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  53. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  54. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  55.